define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'template/index' + location.search,
                    add_url: 'template/add',
                    edit_url: 'template/edit',
                    del_url: 'template/del',
                    multi_url: 'template/multi',
                    table: 'template',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'category_ids', title: __('Category_ids'), searchList: Config.templatelist,operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'createtime', title: __('Createtime') ,operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'user_tags', title: __('User_tags'),  searchList: Config.subjectcategorylist,operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'file_url', title: __('File_url'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'prove',
                                    title: "编辑合同模板",
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    // icon: 'fa fa-check',
                                    text: '编辑合同模板',
                                    url: 'template/docTemplateCreate',
                                    extend: 'data-toggle="tooltip"',
                                    // confirm:'确定要审核通过吗?',
                                    success: function (data, ret) {
                                        // layer.alert(ret.msg);
                                        //如果需要阻止成功提示，则必须使用return false;
                                        // $("#table").bootstrapTable('refreshOptions',{});
                                        // $(".btn-refresh").click();//刷新列表

                                        layer.msg('即将跳转到合同模板编辑页面。。。。', {
                                            icon: 1,
                                            time: 1500,
                                            shade: 0.4
                                        }, function () {
                                            location.href = ret.data.docTemplateEditUrl;
                                        });


                                        return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        layer.alert(ret.msg);
                                        return false;
                                    }
                                },

                            ]
                        }
                    ]
                ]
            });
         $(".search input").attr('placeholder','请输入搜索内容');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
